#include<bits/stdc++.h>
using namespace std;
long long T, ans, n, A[1000005], n, m, L, V;
bool ed[1000005];

int main(){
    ios::sync_with_stdio(false);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> T;
    for(long long i = 1; i <= T; i++){
        ans = 0;
        cin >> n;
        for(long long j = 0; j < n; j++){
            cin >> A[j];
        }
        for(long long j = 0; j < n; j++){
            for(long long k = j + 1; k <= n; k++){
                if(A[j] == A[k] && ed[k] != 1 && ed[j] != 1){
                    ans += A[j];
                    ed[k] = 1;
                    break;
                }
            }
        }
        cout << ans << '\n';
        for(long long j = 0; j < n; j++){
         A[j] = 0;
         ed[j] = 0;
        }
    }
    return 0;
}